home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-12-03 | 2.4 KB | 83 lines | [TEXT/MPS ] |
- {Sample program showing the different ways Pascal can call
- FORTRAN subroutines and fucntions.}
-
- {There are three ways that variables can be passed from
- Pascal to FORTRAN. Passing by reference is FORTRAN's default
- for all types except strings and characters, which are passed
- by descriptor. Starting with Version 2.0, FORTRAN can also
- accept arguments by value, which is Pascal's default.}
-
- { Example provided for owners of Language Systems FORTRAN
- © 1990 Language Systems Corp.}
-
- program PcallsF;
- uses
- MemTypes,
- {$U $$SHELL(PInterfaces)FortTypes.p}
- FortTypes; {Unit that defines FORTRAN Types}
-
- type
- ch20 = packed array[1..20] of char; {Same as CHARACTER*20}
- intary = array[1..100] of integer; {Define an array type}
- COMMON = RECORD
- ia2: intary;
- sum2,i2: integer;
- END;
-
- var
- ca : ch20; {Variable we want the FORTRAN subroutine to set}
- dca : DescRec; {Descriptor to pass to the routine}
- ia : intary; {The array}
- sum : integer; {Total of adding all the array elements}
- i : integer; {Work counter}
- {$J+}
- _TEST_ : Common;
- {Define the FORTRAN subroutines external}
- procedure SumArray(var iary : intary; num: integer;var total : integer);
- External; {1st argument by reference, 2nd by value}
- procedure SumArray2;
- External; {COMMON}
- procedure Charfill(var desc : DescRec);
- External; {character passed by descriptor}
- procedure Charfill2(Var the_char : ch20);
- External; {character passed by reference}
-
- begin
- InitFORTRAN;
- for i:= 1 to 100 do {Fill the array with numbers}
- ia[i] := i;
-
- SumArray(ia,i-1,sum); {Call the subroutine}
-
- writeln('The total is: ',sum); {Display the total}
- for i := 1 to 100 do {Fill the array with numbers}
- _test_.ia2[i] := i;
- _test_.i2 := 100;
- SumArray2; {Call the subroutine}
-
- writeln('The COMMON total is: ',_test_.sum2); {Display the total}
-
- with dca do {Set up the descriptor for the character variable}
- begin
- DataPtr := @ca; {Point to the array}
- DataSize := SizeOf(ca); {Set up the size}
- SymT := chard; {Let the called routine know what it has}
- end;
-
- Charfill(dca); {Call the subroutine and pass the descriptor}
-
- writeln('This is what came back from Charfill:');
- {Display what we got}
- for i := 1 to 20 do
- write(ca[i]);
- writeln;
-
- Charfill2(ca); {Call the subroutine and pass by reference (VAR)}
-
- writeln('This is what came back from Charfill2:');
- {Display what we got}
- for i := 1 to 20 do
- write(ca[i]);
- writeln;
- end.
-